package com.bilin.coin.activity;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.appbar.AppBarLayout;
import com.bilin.coin.R;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.list.CoinDetailList;

import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import butterknife.BindView;

@Route(path = "/safe/DetailActivity")
public class DetailActivity extends BaseAppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.ll_head)
    LinearLayout ll_head;
    @BindView(R.id.sw_refresh)
    SwipeRefreshLayout sw_refresh;
    @BindView(R.id.appbar_layout)
    AppBarLayout appbar_layout;

    @Autowired
    int type;
    @Autowired
    String id;
    @Autowired
    String name;
    CoinDetailList coinDetailList;

    @Override
    protected void initView() {

        setTitle(name+"明细");
        if (name.contains("矿币")) {
            //initHeadMy();
        }
        coinDetailList = new CoinDetailList(this,recyclerView,id);
        coinDetailList.refresh(true);
        initRefresh();

    }

    private void initHeadMy() {
        View headView = View.inflate(this, R.layout.detail_head, null);
        TextView tv_tq = headView.findViewById(R.id.tv_tq);
        TextView tv_tc = headView.findViewById(R.id.tv_tc);
        TextView tv_xwj = headView.findViewById(R.id.tv_xwj);
        TextView tv_ymc = headView.findViewById(R.id.tv_ymc);
        TextView tv_dwj = headView.findViewById(R.id.tv_dwj);
        TextView tv_amount = headView.findViewById(R.id.tv_amount);
        TextView tv_time = headView.findViewById(R.id.tv_time);
        ll_head.addView(headView,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    }

    private void initRefresh() {
        //设置样式刷新显示的位置
        sw_refresh.setProgressViewOffset(true, -20, 100);
        sw_refresh.setOnRefreshListener(this);
        //解决滑动冲突
        appbar_layout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

                if (verticalOffset >= 0) {
                    sw_refresh.setEnabled(true);
                } else {
                    sw_refresh.setEnabled(false);

                }
            }
        });
        sw_refresh.setEnabled(true);
    }


    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.common_recycle_layout_home;
    }

    @Override
    public void onRefresh() {
        sw_refresh.setRefreshing(false);
    }
}
